<?php

namespace Admin\Controller;

class SysController extends BaseController {



  public function mail_set()
  {
    $mailset = M("Mailset")->where(array("id"=>1))->select();
    $this->assign('mailset', $mailset);
    $this->display("Sys/email");
  }

  public function mailset_done()
  {
    $data['host'] = I("post.host");
    $data['username'] = I("post.username");
    $data['password'] = I("post.password");
    $data['from'] = I("post.from");
    $data['fromname'] = I("post.fromname");

    $res = M("Mailset")->where(array("id"=>1))->save($data);
    if($res){
      $this->success('保存成功', U("Sys/mail_set"));
    }else{
      $this->success('未做更改', U("Sys/mail_set"));
    }

  }


  public function licai_set()
  {
    $licaiset = M("Licaiset")->select();
    $this->assign('licaiset', $licaiset);
    $this->display("Sys/licai");
  }

  public function licaiset_done()
  {
    $tj['value'] = I("post.tj");
    M("Licaiset")->where(array("name"=>'tj'))->save($tj);

    for($i=0;$i<11;$i++){
      $str = "td$i";
      $num = "num$i";
      $td['num'] = $_POST[$num];
      $td['value'] = $_POST[$str];
      M("Licaiset")->where(array("name"=>$str))->save($td);
    }
    $this->success('保存成功', U("Sys/licai_set"));

  }


  public function lt_set()
  {
    $fhlist = M("Ltset")->order("id desc")->select();
    $this->assign('fhlist', $fhlist);
    $this->display("Sys/ltset");
  }

  public function ltset_done()
  {
    $data['allmoney'] = I("post.allmoney");
    $data['date'] = time();
    if($data['allmoney'] <= 0){
      $this->error('请填写正确的分红金额!', U("Sys/lt_set"));
    }
    $res = M("Ltset")->add($data);
    if($res){
      //执行分红
      $allusermoney = M("User")->where(array("status"=>0))->sum("usermoney");
      $alluser = M("User")->where(array("status"=>0))->select();
      foreach($alluser as $k=>$v){
        $bl = round($v['usermoney']/$allusermoney,6);
        $fh = round($data['allmoney']*$bl,6);
        if($fh > 0){
          $u['usermoney'] = $v['usermoney']+$fh;
          M("User")->where(array("id"=>$v['id']))->save($u);
          add_log($v['id'], $fh,0, 33, "获得持币分红".$fh);
        }
      }
      $this->success('分红完成!', U("Sys/lt_set"));
    }else{
      $this->error('分红失败!', U("Sys/lt_set"));
    }

  }



  public function gzjs()
  {
    $gzjs = M("Sys")->where(array("name"=>"gzjs"))->getField("value");
    $this->assign('gzjs', $gzjs);
    $this->display("Sys/gzjs");
  }
  public function gzjs_done()
  {
    $gzjs['value'] = I("content");
    $res = M("Sys")->where(array("name"=>"gzjs"))->save($gzjs);
    if($res){
      $this->ajaxReturn("已保存！",'JSON');
    }else{
      $this->ajaxReturn("未作更改！",'JSON');
    }
  }
  public function tjjh()
  {
    $tjjh = M("Sys")->where(array("name"=>"tjjh"))->getField("value");
    $this->assign('tjjh', $tjjh);
    $this->display("Sys/tjjh");
  }
  public function tjjh_done()
  {
    $tjjh['value'] = I("content");
    $res = M("Sys")->where(array("name"=>"tjjh"))->save($tjjh);
    if($res){
      $this->ajaxReturn("已保存！",'JSON');
    }else{
      $this->ajaxReturn("未作更改！",'JSON');
    }
  }
  public function dwsm()
  {
    $dwsm = M("Sys")->where(array("name"=>"dwsm"))->getField("value");
    $this->assign('dwsm', $dwsm);
    $this->display("Sys/dwsm");
  }

  public function dwsm_done()
  {
    $dwsm['value'] = I("content");
    $res = M("Sys")->where(array("name"=>"dwsm"))->save($dwsm);
    if($res){
      $this->ajaxReturn("已保存！",'JSON');
    }else{
      $this->ajaxReturn("未作更改！",'JSON');
    }
  }

  public function yjsm()
  {
    $yjsm = M("Sys")->where(array("name"=>"yjsm"))->getField("value");
    $this->assign('yjsm', $yjsm);
    $this->display("Sys/yjsm");
  }
  public function yjsm_done()
  {
    $yjsm['value'] = I("content");
    $res = M("Sys")->where(array("name"=>"yjsm"))->save($yjsm);
    if($res){
      $this->ajaxReturn("已保存！",'JSON');
    }else{
      $this->ajaxReturn("未作更改！",'JSON');
    }
  }

  public function czsm()
  {
    $czsm = M("Sys")->where(array("name"=>"czsm"))->getField("value");
    $this->assign('czsm', $czsm);
    $this->display("Sys/czsm");
  }

  public function czsm_done()
  {
    $czsm['value'] = I("content");
    $res = M("Sys")->where(array("name"=>"czsm"))->save($czsm);
    if($res){
      $this->ajaxReturn("已保存！",'JSON');
    }else{
      $this->ajaxReturn("未作更改！",'JSON');
    }
  }


  public function txsm()
  {
    $txsm = M("Sys")->where(array("name"=>"txsm"))->getField("value");
    $this->assign('txsm', $txsm);
    $this->display("Sys/txsm");
  }
  public function txsm_done()
  {
    $txsm['value'] = I("content");
    $res = M("Sys")->where(array("name"=>"txsm"))->save($txsm);
    if($res){
      $this->ajaxReturn("已保存！",'JSON');
    }else{
      $this->ajaxReturn("未作更改！",'JSON');
    }
  }


  public function sqxx()
  {
    $sqxx = M("Sys")->where(array("name"=>"sqxx"))->getField("value");
    $this->assign('sqxx', $sqxx);
    $this->display("Sys/sqxx");
  }

  public function sqxx_done()
  {
    $sqxx['value'] = I("content");
    $res = M("Sys")->where(array("name"=>"sqxx"))->save($sqxx);
    if($res){
      $this->ajaxReturn("已保存！",'JSON');
    }else{
      $this->ajaxReturn("未作更改！",'JSON');
    }
  }


}
